package ca.llsutherland.nfl.exception;

import java.util.ArrayList;
import java.util.List;

public class ValidationException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	protected List<PoolMessage> poolMessages = new ArrayList<PoolMessage>();

    protected ValidationException() {
        //default constructor
    }

    public ValidationException(String message) {
        poolMessages.add(new PoolMessage(message));
    }

    public ValidationException(PoolMessage pasMessage) {
        poolMessages.add(pasMessage);
    }

    public ValidationException(List<PoolMessage> pasMessages) {
        this.poolMessages.addAll(pasMessages);
    }

    @Override
    public String getMessage() {
        PoolMessage pasMessage = poolMessages.get(0);
        return pasMessage.getMessage();
    }

    @Override
    public String toString() {
        String retVal = "";
        for (int i = 0; i < poolMessages.size(); i++) {
            PoolMessage pasMessage = poolMessages.get(i);
            retVal += "Message = " + pasMessage.getMessage();
            retVal += "\n";
        }
        return retVal;
    }

    public boolean containsMessage(String expectedMessage) {
        for (PoolMessage pasMessage : poolMessages) {
            if (pasMessage.getMessage().equals(expectedMessage)) {
                return true;
            }
        }
        return false;
    }

    public List<PoolMessage> getPoolMessages() {
        return poolMessages;
    }

}
